{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "<b>Find the perfect gifts for the holiday shopping you've been neglecting</b>\n",
        "\n",
        "With the holidays upon us, some of us might be a little behind in our gift shopping. Gemini can help! Connect to the Gemini API and tell it a bit about the person you want to buy for and Gemini will give you a few suggestions!"
      ],
      "metadata": {
        "id": "ZWhWniBGu3_Y"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Configure Gemini API key\n",
        "\n",
        "#Access your Gemini API key\n",
        "\n",
        "import google.generativeai as genai\n",
        "from google.colab import userdata\n",
        "\n",
        "gemini_api_secret_name = 'GOOGLE_API_KEY'  # @param {type: \"string\"}\n",
        "\n",
        "try:\n",
        "  GOOGLE_API_KEY=userdata.get(gemini_api_secret_name)\n",
        "  genai.configure(api_key=GOOGLE_API_KEY)\n",
        "except userdata.SecretNotFoundError as e:\n",
        "   print(f'Secret not found\\n\\nThis expects you to create a secret named {gemini_api_secret_name} in Colab\\n\\nVisit https://makersuite.google.com/app/apikey to create an API key\\n\\nStore that in the secrets section on the left side of the notebook (key icon)\\n\\nName the secret {gemini_api_secret_name}')\n",
        "   raise e\n",
        "except userdata.NotebookAccessError as e:\n",
        "  print(f'You need to grant this notebook access to the {gemini_api_secret_name} secret in order for the notebook to access Gemini on your behalf.')\n",
        "  raise e\n",
        "except Exception as e:\n",
        "  # unknown error\n",
        "  print(f\"There was an unknown error. Ensure you have a secret {gemini_api_secret_name} stored in Colab and it's a valid key from https://makersuite.google.com/app/apikey\")\n",
        "  raise e\n",
        "\n",
        "model = genai.GenerativeModel('gemini-pro')"
      ],
      "metadata": {
        "id": "yFv1abRcv2P2",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Generate gift suggestions for the person who is hard to shop for\n",
        "\n",
        "interests = \"Running, hiking, being outside\" #@param {type:\"string\"}\n",
        "foods_they_love = \"Chocolate\" #@param {type:\"string\"}\n",
        "items_they_currently_love = \"Sewing machine, anything crafty really\" #@param {type:\"string\"}\n",
        "age = 40 #@param {type:\"slider\", min:0, max:100, step:1}\n",
        "budget = 50 # @param {type:\"integer\"}\n",
        "relation = 'Co-worker' # @param [\"Romantic partner\", \"Child\", \"Parent\", \"Family member\", \"Friend\", \"Co-worker\", \"Other\"]\n",
        "\n",
        "if relation == \"Other\":\n",
        "  relation=\"Acquaintance\"\n",
        "\n",
        "prompt = f\"I'm having a hard time finding a holiday gift for my {relation}\\n\\n\"\n",
        "prompt += f\"Their main interests are {interests} and they love to eat {foods_they_love}\\n\\n\"\n",
        "prompt += f\"Items they use a lot are {items_they_currently_love}\\n\\n\"\n",
        "prompt += f\"They are {age} years old and my budget for them is {budget} dollars\\n\\n\"\n",
        "prompt += \"Could you suggest three good holiday gift ideas that I could buy them?\"\n",
        "prompt += \"Try to be as thoughtful and delightful as possible.\"\n",
        "\n",
        "response = model.generate_content(prompt)\n",
        "\n",
        "#print out the results nicely\n",
        "from IPython.display import Markdown\n",
        "import textwrap\n",
        "\n",
        "def to_markdown(text):\n",
        "  text = text.replace('•', '*')\n",
        "  text = text.replace('$','\\$')\n",
        "  return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))\n",
        "\n",
        "to_markdown(response.text)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 161
        },
        "cellView": "form",
        "id": "Ck92o0KZSMQY",
        "outputId": "2044a947-e681-422a-dc46-7d93a5fc025f"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "> 1. **A Trail-Running Cookbook**(\\$25): Whether they're fueling up for a long run or recovering from a hike, this cookbook has plenty of delicious and nutritious recipes to keep them going. Consider some other trail running or hiking accessories like a new water bottle or a pair of gaiters.\n> \n> 2. **A Craft Subscription Box**(\\$30): This box delivers a curated selection of crafting supplies and instructions to their door each month. There are many different boxes to choose from, so you can find one that fits your co-worker's specific interests.\n> \n> 3. **A Chocolate-Making Kit**(\\$40): This kit has everything they need to make their own chocolate bars, truffles, and other confections. The best part about this gift is it offers an activity and a sweet snack."
          },
          "metadata": {},
          "execution_count": 14
        }
      ]
    }
  ]
}